package com.shanjiduo.newsline.model;

import android.os.Parcel;
import android.os.Parcelable;


import com.shanjiduo.newsline.network.Api;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

import java.util.ArrayList;

/**
 * ITEM的对应可序化队列属性
 */
@Table(name = "ChannelNews")
public class ChannelItem implements Parcelable {

    public static final Creator<ChannelItem> CREATOR = new Creator<ChannelItem>() {
        @Override
        public ChannelItem createFromParcel(Parcel source) {
            return new ChannelItem(source);
        }

        @Override
        public ChannelItem[] newArray(int size) {
            return new ChannelItem[size];
        }
    };

    static {
        ArrayList<ChannelItem> defaultUserChannels = new ArrayList<ChannelItem>();
        ArrayList<ChannelItem> defaultOtherChannels = new ArrayList<ChannelItem>();

        defaultUserChannels.add(new ChannelItem("T1348647909107", "头条", 1, 1));
        defaultUserChannels.add(new ChannelItem("T1348648141035", "军事", 2, 1));
        defaultUserChannels.add(new ChannelItem("5YyX5Lqs", "房产", 3, 1));
        defaultUserChannels.add(new ChannelItem("T1399700447917", "足球", 4, 1));
        defaultUserChannels.add(new ChannelItem("T1348649079062", "体育", 5, 1));
        defaultUserChannels.add(new ChannelItem("T1348648517839", "娱乐", 6, 1));
        defaultUserChannels.add(new ChannelItem("T1348648756099", "财经", 7, 1));
        defaultUserChannels.add(new ChannelItem("T1348649776727", "数码", 8, 1));
        defaultUserChannels.add(new ChannelItem("T1351233117091", "移动", 9, 1));
        defaultUserChannels.add(new ChannelItem("T1356600029035", "彩票", 10, 1));
        defaultUserChannels.add(new ChannelItem("T1348654225495", "教育", 11, 1));
        defaultUserChannels.add(new ChannelItem("T1349837670307", "论坛", 12, 1));
        defaultUserChannels.add(new ChannelItem("T1348654204705", "旅游", 13, 1));
        defaultUserChannels.add(new ChannelItem("T1348649654285", "手机", 14, 1));
        defaultUserChannels.add(new ChannelItem("T1349837698345", "博客", 15, 1));
        defaultUserChannels.add(new ChannelItem("T1348648037603", "社会", 16, 1));
        defaultUserChannels.add(new ChannelItem("T1348654105308", "家居", 17, 1));
        defaultUserChannels.add(new ChannelItem("T1397016069906", "暴雪", 18, 1));
        defaultUserChannels.add(new ChannelItem("T1397116135282", "亲子", 19, 1));
        defaultUserChannels.add(new ChannelItem("T1348649475931", "CBA", 20, 1));
        defaultUserChannels.add(new ChannelItem("T1348648141035", "消息", 21, 1));

        defaultOtherChannels.add(new ChannelItem("T1348649580692", "科技", 1, 0));
        defaultOtherChannels.add(new ChannelItem("T1348648650048", "电影", 2, 0));
        defaultOtherChannels.add(new ChannelItem("T1348654060988", "汽车", 3, 0));
        defaultOtherChannels.add(new ChannelItem("T1350383429665", "笑话", 4, 0));
        defaultOtherChannels.add(new ChannelItem("T1348654151579", "游戏", 5, 0));
        defaultOtherChannels.add(new ChannelItem("T1348650593803", "时尚", 6, 0));
        defaultOtherChannels.add(new ChannelItem("T1348650839000", "情感", 7, 0));
        defaultOtherChannels.add(new ChannelItem("T1348649145984", "NBA", 8, 0));
        defaultOtherChannels.add(new ChannelItem("T1370583240249", "精选", 9, 0));
        defaultOtherChannels.add(new ChannelItem("T1379038288239", "电台", 10, 0));
    }

    /**
     * 栏目对应ID
     */
    @Column(name = "id", isId = true)
    public int id;

    @Column(name = "newsId")
    public String newsId;
    /**
     * 栏目对应NAME,对应的标题
     */
    @Column(name = "name")
    public String name;
    /**
     * 栏目在整体中的排序顺序  rank
     */
    @Column(name = "orderId")
    public int orderId;
    /**
     * 栏目是否选中
     */
    @Column(name = "selected")
    public int selected;

    public ChannelItem() {
    }

    public ChannelItem(String name, int orderId, int selected) {
        this.name = name;
        this.orderId = orderId;
        this.selected = selected;
    }

    public ChannelItem(String newsId, String name, int orderId, int selected) {
        this.newsId = newsId;
        this.name = name;
        this.orderId = orderId;
        this.selected = selected;
    }

    protected ChannelItem(Parcel in) {
        this.id = in.readInt();
        this.newsId = in.readString();
        this.name = in.readString();
        this.orderId = in.readInt();
        this.selected = in.readInt();
    }

    /**
     * 新闻类别获取类型
     *
     * @return
     */
    public String getType() {
        switch (newsId) {
            case Api.HEADLINE_ID:
                return Api.HEADLINE_TYPE;
            case Api.HOUSE_ID:
                return Api.HOUSE_TYPE;
            default:
                break;
        }
        return Api.OTHER_TYPE;
    }

    public String getNewsId() {
        if (newsId == Api.HOUSE_ID) return "北京";
        return newsId;
    }

    public void setNewsId(String newsId) {
        this.newsId = newsId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public int getSelected() {
        return selected;
    }

    public void setSelected(int selected) {
        this.selected = selected;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.id);
        dest.writeString(this.newsId);
        dest.writeString(this.name);
        dest.writeInt(this.orderId);
        dest.writeInt(this.selected);
    }

    @Override
    public String toString() {
        return "ChannelItem{" +
                "id=" + id +
                ", newsId='" + newsId + '\'' +
                ", name='" + name + '\'' +
                ", orderId=" + orderId +
                ", selected=" + selected +
                '}';
    }
}